
#ifndef __TIMER_H__
#define __TIMER_H__

#include "define.h"


class timer {
public:
  timer();
  		
public:
  void set_elapse(xuint16 elapse) { m_elapse = elapse; MCCNT = m_elapse;}// 1/3 microsecond when bus = 24MHz
  xuint16 get_elapse(){ return m_elapse; }
  void start(){ MCCTL_MCEN=1; }
  void pause(){ MCCTL_MCEN=0; }
  void refresh()
  { 
    MCFLG = 0x80;
    MCCNT = m_elapse;
    m_count++;
    if (m_count==60000) m_count = 0;
  }
  xuint8 base(xuint16 b) { return (m_count%b == 0)?1:0;}
  
private:
  xuint16 m_elapse;
  xuint16 m_count;
};

#endif